const fn = (state = {
  list:[],
  title: '要闻',
  topList: [],
  page:'',
  allPage:'',
  flag:true
}, {type, data}) => {
  switch (type) {
    case 'CHANGE_TOPLIST' :
      state = {
        list: state.list,
        topList: data,
        title: state.title,
        page: state.page,
        allPage: state.allPage
      }
      return state;
    case 'UPDATE_LIST' :
      let list = state.list
      // console.log(data.page)
      if (data.page !== 1){
        data.newsList.forEach(item => {
          list.push(item)
        })
      } else if (data.page === 1) {
        list = data.newsList
      }
      // console.log(list)
      state = {
        list: list,
        topList: state.topList,
        title: state.title,
        page: data.page,
        allPage: data.allPage
      }
      return state;
    case 'CHANGE_TITLE':
      state = {
        list: state.list,
        topList: state.topList,
        title: data,
        page: state.page,
        allPage: state.allPage
      }
      return state;
    case 'CHANGE_PAGE' :
      state = {
        list: state.list,
        topList: state.topList,
        title: state.title,
        page: data,
        allPage: state.allPage
      }
      return state;
    default:
      return state;
  }
}

export default fn